package com.cookbook.service.impl;

import com.cookbook.database.data.CommentMapper;
import com.cookbook.database.data.ReplyMapper;
import com.cookbook.database.model.Comment;
import com.cookbook.database.model.Reply;
import com.cookbook.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 毛川
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    CommentMapper commentMapper;

    @Autowired
    ReplyMapper replyMapper;

    @Override
    public void insert(Comment comment) {
        commentMapper.insert(comment);
    }

    @Override
    public void insert(Reply reply) {
        replyMapper.insert(reply);
    }

    @Override
    public List<Comment> commentsWithOffset(Integer shareId, Integer page, Integer limit) {
        int offset = page * limit;
        return commentMapper.selectWithOffset(shareId, offset, limit);
    }

    @Override
    public List<Reply> repliesWithOffset(Integer commentId, Integer page, Integer limit) {
        int offset = page * limit;
        return replyMapper.selectWithOffset(commentId, offset, limit);
    }
}
